package com.xinlin.framework.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.security.core.Authentication;

import java.util.HashMap;
import java.util.Map;

public class JwtTokenGenerator {
    public String generateToken(Authentication auth, String userType) {
        Map<String, Object> claims = new HashMap<>();
        claims.put("userType", userType); // 标识用户类型（system/app）
        claims.put("authorities", auth.getAuthorities());
        
        return Jwts.builder()
            .setClaims(claims)
            .setSubject(auth.getName())
            .signWith(SignatureAlgorithm.HS512, "SECRET_KEY")
            .compact();
    }
}
